package com.szsfm.vehiclemanagement.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.szsfm.vehiclemanagement.R;
import com.szsfm.vehiclemanagement.bean.Message;
import com.szsfm.vehiclemanagement.viewholder.MessageHolder;

import java.util.List;

/**
 * Created by zhoubigbo on 2017/11/21.
 */
public class MessageAdapter extends RecyclerView.Adapter<MessageHolder> {

    List<Message> mMessages;
    Context mContext;
    LayoutInflater mInflater;

    public MessageAdapter(Context context,List<Message> messages) {
        this.mContext = context;
        this.mMessages = messages;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public void onBindViewHolder(MessageHolder holder, int position) {
        Message message=mMessages.get(position);
        holder.mTitleText.setText(message.getTitle()+":");
        holder.mContentText.setText(message.getMessage());
    }

    @Override
    public int getItemCount() {
        return mMessages.size();
    }

    @Override
    public MessageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View contentView = this.mInflater.inflate(R.layout.item_message_recycle_view,parent,false);
        MessageHolder messageHolder = new MessageHolder(contentView);
        return messageHolder;
    }

    public void addItem(Message item) {
        mMessages.add(item);
        notifyDataSetChanged();
    }
}
